<template>
	<view class="container">
		<view class="bg1">
			<view></view>
		</view>
		<view class="dian"></view>
		<view class="header">
			<image src="https://www.guizhouqy.com/mini/back.png" @click="back" mode=""></image>
			<text>更换密码</text>
			<image src="" mode=""></image>
		</view>
		<div class="form">
			<uni-forms ref="baseForm" :modelValue="userForm" :label-position="alignment">
				<uni-forms-item label="旧密码">
					<uni-easyinput type="password" :inputBorder="false" v-model="userForm.old_pwd"/>
				</uni-forms-item>
				<uni-forms-item label="新密码">
					<uni-easyinput type="password" :inputBorder="false" v-model="userForm.new_pwd"/>
				</uni-forms-item>
				<uni-forms-item label="重复新密码" label-width="200px">
					<uni-easyinput type="password" :inputBorder="false" v-model="userForm.re_pwd"/>
				</uni-forms-item>
				<button @click="submit" type="primary" style="background: linear-gradient(313deg, #7116E9 0%, #15D1E2 100%);border-radius: 16rpx 16rpx 16rpx 16rpx;">确认更换</button>
			</uni-forms>
		</div>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userForm: {
					old_pwd: '',
					new_pwd: '',
					re_pwd: ''
				},
				alignment: 'top',
				showPassword: true
			}
		},
		mounted() {
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				});
			},
			
			// 保存
			async submit() {
				
				if (this.userForm.old_pwd == '') {
					this.$tool.error('请输入旧密码');
					return false;
				}
				
				if (this.userForm.new_pwd == '') {
					this.$tool.error('请输入新密码');
					return false;
				}
				
				if (this.userForm.re_pwd == '') {
					this.$tool.error('请再次输入新密码');
					return false;
				}
				
				if (this.userForm.new_pwd != this.userForm.re_pwd) {
					this.$tool.error('两次密码输入不一致');
					return false;
				}
				
				let res = await this.$api.user.changePassword.post(this.userForm)
				if (res.code == 0) {
					this.$tool.success('更换成功');
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/set/set'
						}) 
					}, 800)
				} else {
					this.$tool.error(res.msg);
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		background: #f5f5f5;
	}
	.container {
		height: 100%;
		width: 100%;
		padding: 0 26rpx;
		color: #FFFFFF;
		background: #240F41;
		
		.bg1 {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			position: absolute;
			left: calc(50%-59px);
		
			view {
				width: 118px;
				height: 118px;
				background: linear-gradient(90deg, #C829F3 0%, #4516CA 100%);
				box-shadow: inset 0rpx 8rpx 8rpx 0rpx rgba(0, 0, 0, 0.25);
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				opacity: 0.9;
				filter: blur(90px);
			}
		}
		
		.dian {
			width: 118px;
			height: 118px;
			background: linear-gradient(90deg, #1F87EF 0%, #1F87EF 100%);
			box-shadow: inset 0rpx 8rpx 8rpx 0rpx rgba(0, 0, 0, 0.25);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			opacity: 0.9;
			filter: blur(90px);
			position: absolute;
			left: 0;
			top: 20px;
		}
		
		.header {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			padding-top: 30px;
			margin-bottom: 26rpx;
		
			image {
				width: 48rpx;
				height: 48rpx;
				z-index: 999;
			}
		}
	}
	.form {
		width: 100%;
		margin: 0 auto;
		padding: 26rpx;
		
		.uni-forms-item__label {
			color: #FFFFFF;
		}
		
		.uni-easyinput__content {
			width: 100%;
			height: 88rpx;
			color: #FFFFFF;
			background: linear-gradient( 180deg, rgba(154,36,185,0.2) 0%, rgba(133,22,233,0.2) 100%) !important;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			border: 2rpx solid #9A24B9 !important;
			padding: 16rpx;
		}
	}
</style>